import { getTableInfo } from '../../api/projectRole'

const state = {
  tableData: [],
  total: '',
  index: '',
  sysRoleDTO: {
    createTime: '',
    isValid: 0,
    remark: '',
    roleName: '',
    roleSign: '',
    updateTime: '',
    webMenuList: [
      {
        component: '',
        createTime: '',
        isValid: 0,
        parentId: 0,
        path: '',
        perms: '',
        remark: '',
        updateTime: '',
        webMenuId: 0,
        webMenuName: ''
      }
    ],
    webMenuIds: []
  },
  webMenuList: []
}

const mutations = {
  // 设置更新列表
  update_list (state, tableData) {
    state.tableData = tableData
  },
  // 总数
  list_count (state, total) {
    state.total = total
  }
}

const actions = {
  // 刷新列表
  updateTable (context, index) {
    return new Promise((resolve, reject) => {
      getTableInfo(index, 10).then(res => {
        if (res.data.code === (200 || '200')) {
          context.commit('update_list', res.data.data.data)
          context.commit('list_count', res.data.data.count)
        }
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  }
}
export default {
  namespaced: true,
  actions,
  state,
  mutations
}
